<!--
 * @Author: 朱自强
 * @Date: 2023-04-20 11:58:35
 * @LastEditors: 朱自强
 * @LastEditTime: 2024-03-13 19:39:09
 * @FilePath: \A-LOT-OF-TEST-VUE3\src\components\Aggrid\AgRender\AgRender.vue
 * @Description: 
 * 
 * Copyright (c) 2023 by 朱自强, All Rights Reserved. 
-->
<template>
  <div :id="`ag-render-div-${uuid}`">
    <!-- 性别 -->
    <template v-if="renderField === 'sex'">
      <span>{{ currPrarams.data.sex === 1 ? '男' : '女' }}</span>
    </template>
  </div>
</template>

<script lang="ts" setup>
import type { Ref } from 'vue'
import type { ICellRendererParams } from 'ag-grid-community'
import { ref, watch } from 'vue'
import { getUUID } from '@/utils/utils'
// 唯一标识
const uuid: string = getUUID()
// 参数
const currPrarams: Ref<ICellRendererParams | any> = ref(null)
// 渲染你字段
const renderField: Ref<string> = ref('')
// 当前行数据
const currRow: Ref<any> = ref(null)
// 属性
const props = defineProps({
  // ag默认参数
  params: {
    type: Object,
    default: null
  }
})
// 监听params
watch(
  () => props.params,
  (newVal: any) => {
    // console.log('渲染参数', newVal)
    // 参数
    currPrarams.value = newVal
    // 渲染字段
    renderField.value = newVal.colDef.field
    // 当前行数据
    currRow.value = newVal.data
  },
  { immediate: true }
)
// 向外部暴露方法
defineExpose({})
</script>

<style lang="less" scoped></style>
<style></style>
